import Vue from 'vue'

Vue.mixin({
  computed: {
    deBounceWrap() {
      return this._.debounce((fun, ...args) => fun.apply(this, args), 300, {
        leading: true,
        trailing: false
      })
    }
  },
  methods: {
    // 操作成功消息提醒内容
    submitOk(msg, cb) {
      this.$notify({
        title: '成功',
        message: msg,
        type: 'success',
        duration: 2000,
        onClose: function() {
          cb && cb()
        }
      })
    },
    // 操作失败消息提醒内容
    submitFail(msg) {
      this.$message({
        message: msg,
        type: 'error'
      })
    },
    /**
     * filterObjNull
     * @desc 过滤对象中的空值
     * @param obj 需要过滤的对象
     */
    filterObjNull(obj = {}) {
      const result = {}
      Object.keys(obj).map(key => {
        if (!(!obj[key] && String(obj[key]) === '')) {
          result[key] = obj[key]
        }
      })
      return result
    }
  }
})
